function queryBook(){  
   var mydata = '{"queryParams":"' + $("#condition").val() + '"}';
   $.ajax({                   
	   type:'post',                   
	   url:'/bms/bookquery/booklist',//URL                 
	   data:mydata,                
	   dataType:'json',
	   contentType : "application/json; charset=utf8",
	   success:function(data) { 		      
		       var bf=data.bf;	
		       var availQuan=data.availQuan;	       
			   createShowingTable(bf,availQuan);
		    }
	   });
  }

function createShowingTable(data,availQuan) {
	var tStrStart = "<div class='table-responsive'><table class='table table-bordered table-hover'><thead><tr><th>" + "#" + "</th>" + "<th>" +"Book Name" + "</th>" + "<th>" + "Book Type" + "</th>" + "<th>" + "Author"
				+ "</th>" + "<th>"+"Publisher"+"</th>" + "<th>"+"Price"+"</th>" + "<th>"+"City"+"</th>" + "<th>" +"Available Quantity"+"</td>"
				+"<th>"+"Comment"+"</th><th>"+"DeleteDateTime"+"</th><th>"+"Borrow"+"</th>"+"</tr></thead><tbody>";
	var booksString;	
	$.each(data, function(n, book) {
		 var number=parseInt(n);
		 number=number+1;
		 var deleteDateTime="";
		 if(book.deleteDateTime!=null){
			 deleteDateTime=book.deleteDateTime;
		 }
		if(book.deleteDateTime==null){
			if(availQuan[n]!=0){
				booksString="<tr><td>"+number+"</td><td>"+book.name+"</td><td>"+book.bookType.name+"</td><td>"+book.author+"</td><td>"+book.publisher+"</td><td>"
		        +book.price+"</td><td>"+book.city+"</td><td>"+availQuan[n]+"</td><td>"+book.comment+"</td><td>"+deleteDateTime+"</td>" 
		        +"<td style='width:70px'><a class='btn mini green' href='/bms/borrowreturninfo/borrowconfirm?id="+book.id+"&availQuantity="+availQuan[n]+"'>Borrow</a></td>"+"</tr>";			
			}else{
				booksString="<tr><td>"+number+"</td><td>"+book.name+"</td><td>"+book.bookType.name+"</td><td>"+book.author+"</td><td>"+book.publisher+"</td><td>"
		        +book.price+"</td><td>"+book.city+"</td><td>"+availQuan[n]+"</td><td>"+book.comment+"</td><td>"+deleteDateTime+"</td>" 
		        +"<td></td>"+"</tr>";						
			}	
		}else{
			booksString="<tr><td>"+number+"</td><td>"+book.name+"</td><td>"+book.bookType.name+"</td><td>"+book.author+"</td><td>"+book.publisher+"</td><td>"
	        +book.price+"</td><td>"+book.city+"</td><td>"+availQuan[n]+"</td><td>"+book.comment+"</td><td>"+deleteDateTime+"</td>" 
	        +"<td></td>"+"</tr>";	
		}	 
		tStrStart = tStrStart + booksString;      
	});
	var tStrEnd="</tbody></table></div>";
	tStrStart=tStrStart+tStrEnd;
	$("#books").html(tStrStart);
}
function doClear(){
	$("#condition").attr("value","");
	$("#books").empty();
}
   

 
